package cn.edu.scau.cmi.linpeiwei.controller;

import javafx.fxml.FXML;

import javafx.scene.control.Button;

import javafx.scene.text.Text;

import javafx.scene.control.TextField;
import javafx.scene.layout.AnchorPane;

import java.util.HashSet;
import java.util.Set;

import cn.edu.scau.cmi.linpeiwei.multiton.Marshal;
import javafx.event.ActionEvent;

public class MultitonController extends AnchorPane{
	@FXML
	private Button mybtn;
	@FXML
	private TextField mytextfield;
	@FXML
	private Text mytext;
	@FXML
	private Text mytext2;

	private Set<Marshal> marshals = new HashSet<>();

//	public MultitonController() {
//		marshals = Marshal.getMarshal("���");
//		marshals = Marshal.getMarshal("��»�");
//		marshals = Marshal.getMarshal("�ֱ�");
//		marshals = Marshal.getMarshal("������");
//		marshals = Marshal.getMarshal("Ҷ��Ӣ");
//		marshals = Marshal.getMarshal("����");
//		marshals = Marshal.getMarshal("����");
//		marshals = Marshal.getMarshal("���ٻ�");
//		marshals = Marshal.getMarshal("����ǰ");
//		marshals = Marshal.getMarshal("������");
//	}

	// Event Listener on Button[#mybtn].onAction
	@FXML
	public void eventButton(ActionEvent event) {
		String name = "";
		
		if (mytextfield.getText().isEmpty()) {
			mytext2.setText("请输入名字");
			mytext2.setVisible(true);
		}
		else if (marshals.size()>=10) {
			mytext2.setText("已超过10个");
			mytext2.setVisible(true);
		}
		else {
			mytext2.setVisible(false);
			marshals = Marshal.getMarshal(mytextfield.getText());
			for (Marshal m : marshals) {
				name = name + m.getName() + '\n';
				mytext.setText(name);
			}
		}
		mytext.setVisible(true);
		mytextfield.clear();
	}
}
